<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件上传下载测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .test-section {
            margin: 20px 0;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        .file-bubble {
            background: #f0f0f0;
            border-radius: 7.5px;
            padding: 15px;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            max-width: 260px;
            min-width: 200px;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            position: relative;
            margin: 5px 0;
        }
        .file-bubble:hover {
            transform: translateY(-2px);
            box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
        }
        .file-icon {
            font-size: 40px;
            margin-right: 15px;
            color: #128C7E;
        }
        .file-info {
            flex: 1;
            min-width: 0;
        }
        .file-name {
            font-weight: 500;
            margin-bottom: 6px;
            font-size: 15px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .file-size {
            font-size: 13px;
            color: #666;
            margin-bottom: 8px;
        }
        .upload-complete {
            color: #128C7E;
            font-weight: 500;
        }
        .upload-complete i {
            margin-right: 5px;
        }
        .download-message {
            position: fixed;
            top: 20px;
            right: 20px;
            background: #4CAF50;
            color: white;
            padding: 10px 15px;
            border-radius: 5px;
            z-index: 9999;
            box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        }
    </style>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body>
    <h1>文件上传下载功能测试</h1>
    
    <div class="test-section">
        <h2>1. 文件上传测试</h2>
        <input type="file" id="testFileInput">
        <button onclick="testUpload()">测试上传</button>
        <div id="uploadResult"></div>
    </div>
    
    <div class="test-section">
        <h2>2. 文件下载测试</h2>
        <input type="text" id="testFileName" placeholder="输入文件名" value="test.txt">
        <button onclick="testDownload()">测试下载</button>
        <div id="downloadResult"></div>
    </div>
    
    <div class="test-section">
        <h2>3. 文件气泡显示测试</h2>
        <button onclick="showFileBubble()">显示文件气泡</button>
        <div id="fileBubbleContainer"></div>
    </div>

    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script>
        function testUpload() {
            const fileInput = document.getElementById('testFileInput');
            const file = fileInput.files[0];
            
            if (!file) {
                alert('请选择文件');
                return;
            }
            
            const formData = new FormData();
            formData.append('file', file);
            
            $.ajax({
                type: 'POST',
                url: '/file/upload',
                data: formData,
                processData: false,
                contentType: false,
                success: function(response) {
                    if (response && response.content) {
                        document.getElementById('uploadResult').innerHTML = 
                            `<p style="color: green;">上传成功！文件名: ${response.content}</p>`;
                    } else {
                        document.getElementById('uploadResult').innerHTML = 
                            `<p style="color: red;">上传失败</p>`;
                    }
                },
                error: function() {
                    document.getElementById('uploadResult').innerHTML = 
                        `<p style="color: red;">上传失败: 网络错误</p>`;
                }
            });
        }
        
        function testDownload() {
            const fileName = document.getElementById('testFileName').value;
            
            if (!fileName) {
                alert('请输入文件名');
                return;
            }
            
            $.ajax({
                type: 'GET',
                url: '/file/download',
                data: {
                    fileName: fileName
                },
                success: function(response) {
                    if (response && response.content) {
                        document.getElementById('downloadResult').innerHTML = 
                            `<p style="color: green;">获取下载链接成功！</p>
                             <p>下载链接: ${response.content}</p>
                             <button onclick="downloadFile('${response.content}', '${fileName}')">点击下载</button>`;
                    } else {
                        document.getElementById('downloadResult').innerHTML = 
                            `<p style="color: red;">获取下载链接失败</p>`;
                    }
                },
                error: function() {
                    document.getElementById('downloadResult').innerHTML = 
                        `<p style="color: red;">获取下载链接失败: 网络错误</p>`;
                }
            });
        }
        
        function downloadFile(downloadUrl, fileName) {
            const link = document.createElement('a');
            link.href = downloadUrl;
            link.download = fileName;
            link.target = '_blank';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            
            showDownloadMessage(`文件下载成功: ${fileName}`);
        }
        
        function showFileBubble() {
            const container = document.getElementById('fileBubbleContainer');
            const bubble = $(`
                <div class="file-bubble completed">
                    <div class="file-icon">
                        <i class="fas fa-file"></i>
                    </div>
                    <div class="file-info">
                        <div class="file-name">test-document.pdf</div>
                        <div class="file-size">2.5MB</div>
                        <div class="upload-complete">
                            <i class="fas fa-check-circle"></i>
                            点击下载
                        </div>
                    </div>
                </div>
            `);
            
            bubble.on('click', function() {
                testDownload();
            });
            
            container.innerHTML = '';
            container.appendChild(bubble[0]);
        }
        
        function showDownloadMessage(message) {
            const messageDiv = $(`<div class="download-message">${message}</div>`);
            $('body').append(messageDiv);
            
            setTimeout(function() {
                messageDiv.fadeOut(function() {
                    $(this).remove();
                });
            }, 3000);
        }
    </script>
</body>
</html> 